home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE01 / TIPTRIX / DLLOBJ / MYOBJ.PAS next >
Encoding:
Pascal/Delphi Source File  |  1995-06-01  |  2.0 KB  |  85 lines

  1. unit MyObj;
  2.  
  3. interface
  4.  
  5. {$IFNDEF EXPORT}
  6.   {$IFNDEF IMPORT}
  7.     {$DEFINE NORMAL}
  8.   {$ENDIF}
  9. {$ENDIF}
  10.  
  11. type
  12.   TMyObject = class(TObject)
  13.   private
  14.     FProp : integer;
  15.     procedure SetProp(Value: integer); virtual;
  16.                       {$IFNDEF NORMAL} export;   {$ENDIF}
  17.                       {$IFDEF  IMPORT} abstract; {$ENDIF}
  18.   public
  19.     constructor Create;                virtual;
  20.                       {$IFNDEF NORMAL} export;   {$ENDIF}
  21.                       {$IFDEF  IMPORT} abstract; {$ENDIF}
  22.     destructor Destroy;                virtual;
  23.                       {$IFNDEF NORMAL} export;   {$ENDIF}
  24.                       {$IFDEF  IMPORT} abstract; {$ENDIF}
  25.     procedure  Free;                   virtual;
  26.                       {$IFNDEF NORMAL} export;   {$ENDIF}
  27.                       {$IFDEF  IMPORT} abstract; {$ENDIF}
  28.     procedure TestIt;                  virtual;
  29.                       {$IFNDEF NORMAL} export;   {$ENDIF}
  30.                       {$IFDEF  IMPORT} abstract; {$ENDIF}
  31.     property Prop: integer read FProp write SetProp;
  32.   end;
  33.   TMyObjectClass = class of TMyObject;
  34.  
  35. function _TMyObject: TMyObjectClass; {$IFDEF EXPORT} export; {$ENDIF}
  36.  
  37. implementation
  38.  
  39. uses
  40.   WinProcs;
  41.  
  42. {$IFNDEF IMPORT}
  43. constructor TMyObject.Create;
  44. begin
  45.   inherited Create; { Call the non-virtual TObject.Create here }
  46.   FProp := 1;
  47. end;
  48.  
  49. destructor TMyObject.Destroy;
  50. begin
  51.   inherited Destroy; { Call the virtual destructor TObject.Destroy }
  52. end;
  53.  
  54. procedure  TMyObject.Free;
  55. begin
  56. { if Self = nil, then we wouldn't be here in the first place }
  57.   Destroy;
  58. end;
  59.  
  60. procedure TMyObject.TestIt;
  61. var
  62.   i : integer;
  63. begin
  64.   for i := 1 to FProp do
  65.     WinProcs.MessageBeep(0);
  66. end;
  67.  
  68. procedure TMyObject.SetProp(Value: integer);
  69. begin
  70.   if Value > 10 then
  71.     FProp := 10
  72.   else
  73.     FProp := Value;
  74. end;
  75. {$ENDIF}
  76.  
  77. function _TMyObject: TMyObjectClass; {$IFDEF IMPORT} external 'OBJDLL' index 1;
  78. {$ELSE}
  79. begin
  80.   Result := TMyObject;
  81. end;
  82. {$ENDIF}
  83.  
  84. end.
  85.